import React from 'react';
import { useEffect, useState } from 'react';
import { useHistory } from 'umi';

export default function Nowplaying() {
  const [list, setlist] = useState([]);
  const history = useHistory()

  useEffect(() => {
    fetch(
      'https://m.maizuo.com/gateway?cityId=110100&pageNum=1&pageSize=10&type=1&k=8614587',
      {
        headers: {
          'X-Client-Info':
            '{"a":"3000","ch":"1002","v":"5.2.1","e":"1677227170557439510380545","bc":"110100"}',
          'X-Host': 'mall.film-ticket.film.list',
        },
      },
    )
      .then((res) => res.json())
      .then((res) => {
        // console.log(res.data.films);
        setlist(res.data.films);
      });
  }, []);

  return (
    <div>
      {
        list.map((item: any) => {
          return <li key={item.filmId} onClick={() => {
            history.push(`/detail/${item.filmId}`)
          }}>{item.name}</li>;
        })
      }
    </div>
  );
}
